package common;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;

import java.security.KeyPair;
import java.security.interfaces.RSAPublicKey;
import java.util.Map;

public class JksUtils {
    public static Map<String,Object>  getUserInfoByToken(String token) {
        Map<String,Object> body=null;
        try {
            ClassPathResource classPathResource = new ClassPathResource("huaweishop.jks");
            KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(classPathResource, "huaweishop".toCharArray());
            KeyPair keyPair = keyStoreKeyFactory.getKeyPair("huaweishop");
            RSAPublicKey publicKey = (RSAPublicKey)keyPair.getPublic();
            Jws<Claims> claimsJws= Jwts.parser().setSigningKey(publicKey).parseClaimsJws(token);
            body=claimsJws.getBody();
        }catch (Exception e){

        }
        return body;
    }
}
